package com.pzl.controller;

import com.pzl.entity.Role;
import com.pzl.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * RoleController class
 *
 * @Author panzhenglei
 * @Date 2019/6/8 10:26 AM
 */

@Controller
@RequestMapping("/role")
public class RoleController {
        @Autowired
    private RoleService roleService;
 /*   public void sate(){
        String s = new String();
    }*/


 @RequestMapping("/list")
 public ModelAndView findAll(){
     ModelAndView modelAndView = new ModelAndView();

     List<Role> role = roleService.findAll();
     modelAndView.addObject("role",role);
     modelAndView.setViewName("role-list");

     return modelAndView;
 }

    @RequestMapping("/save")
    public ModelAndView save(String roleName,String roleDesc) throws Exception {
        System.out.println(roleName+"  "+roleDesc);
        ModelAndView modelAndView = new ModelAndView();
        Long save = roleService.save(roleName, roleDesc);
        List<Role> role = roleService.findAll();
        modelAndView.addObject("role",role);
        modelAndView.setViewName("role-list");

        return modelAndView;
    }

}
